/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import { Button, message } from 'antd';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import EditForm from './components/EditForm';

let editForm: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ itemTrailerFee, dispatch }) => (
  <div>
    <StandardModule
      data={itemTrailerFee.data}
      dictionary={[
        {
          name: 'gysNameCode',
          desc: '供应商名称/代码',
          dataType: 'string',
        },
        {
          name: 'zhuangguiAddress',
          desc: '装柜地址',
          dataType: 'string',
        },
        {
          name: 'loadingPort',
          desc: '出货港口',
          dataType: 'string',
        },
        {
          name: 'fee_20Gp',
          desc: '20Gp',
          dataType: 'string',
        },
        {
          name: 'fee_40GP',
          desc: '40GP',
          dataType: 'string',
        },
        {
          name: 'fee_40HQ',
          desc: '40HQ',
          dataType: 'string',
        },
        {
          name: 'xianzhong',
          desc: '限重',
          dataType: 'string',
        },
        {
          name: 'beginTime',
          desc: '开始时间',
          dataType: 'string',
        },
        {
          name: 'endTime',
          desc: '结束时间',
          dataType: 'string',
        },
      ]}
      config={{
        common: {
          formItemOptions: {
            goodsType: {
              rules: [{ required: true, message: '该字段不能为空！' }],
            },
          },
        },
        search: {
          fields: ['gysNameCode', 'loadingPort', 'zhuangguiAddress', 'beginTime', 'endTime'], // 查询条件
          tabs: {
            field: 'status',
            tabItems: [
              {
                title: '全部',
                value: '',
                active: true,
              },
              {
                title: '待审核',
                value: 'TO_AUDIT',
              },
              {
                title: '审核通过',
                value: 'AUDIT_PASS',
              },
              {
                title: '审核失败',
                value: 'AUDIT_FAIL',
              },
              {
                title: '已上架',
                value: 'ONLINE',
              },
              {
                title: '已下架',
                value: 'OFFLINE',
              },
            ],
          }, // 状态栏
        },
        list: {
          url: '/api/itemTrailerFee/query',
          fields: [
            'id',
            'gysNameCode',
            'zhuangguiAddress',
            'loadingPort',
            'fee_20Gp',
            'fee_40GP',
            'fee_40HQ',
            'xianzhong',
            'status',
            'beginTime',
            'endTime',
          ], // 列表字段
          format: {
            id: {
              width: 70,
              fixed: 'left',
            },
            operations: {
              width: 350,
            },
          },
          table: {
            // Table组件属性
            scroll: { x: 2300 },
          },
          extensions: {
            operations: [
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  详情
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  审核
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  上架
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  下架
                </a>
              ),
            ],
          },
        },
        update: {
          url: '/api/itemTrailerFee/update',
          // width: 680, // 非必填，默认680px
          // title: '新建表单', // 非必填，默认`新建`
          fields: [
            'zhuangguiAddress',
            'loadingPort',
            'fee_20Gp',
            'fee_40GP',
            'fee_40HQ',
            'xianzhong',
            'beginTime',
            'endTime',
          ], // 修改表单字段
          primaryKeys: ['id'], // 主键字段列表
        },
        delete: {
          url: '/api/itemTrailerFee/remove',
          batchDelete: false, // 是否开启批量删除
          fields: ['id'], // 删除依据字段
        },
        extensions: {
          operations: [
            // 外层操作
            (selectedRows: [], search: () => void) => (
              <div>
                <Button
                  key={1}
                  type="primary"
                  onClick={() => {
                    if (editForm) editForm.handleOpen();
                  }}
                >
                  新增
                </Button>
              </div>
            ),
          ],
        },
      }}
      namespace="itemTrailerFee"
      dispatch={dispatch}
    />
    {/* eslint-disable-next-line no-return-assign */}
    <EditForm wrappedComponentRef={(inst: any) => (editForm = inst)} {...editForm} visible />
  </div>
);

// @ts-ignore
export default connect(({ itemTrailerFee }) => ({
  itemTrailerFee,
}))(LocalModule);
